#pragma once
#include "pw_async2/coro_or_else_task.h"
#include "pw_async2/dispatcher.h"
#include "awaitable.hpp"
namespace coro{
struct Runnable {
  static auto Instance() -> Runnable & {
    static Runnable ins;
    return ins;
  }
  
  template <typename... TTask> auto Start(TTask &...task) -> Runnable & {
    (m_dispatch.Post(task), ...);
    return *this;
  }

  auto Join() { m_dispatch.RunToCompletion(); }
  auto UntilStalled() { return m_dispatch.RunUntilStalled(); }
  auto NumberOfCompleted() {
    return m_dispatch.tasks_completed();
  }

private:
  Runnable() {}
  pw::async2::Dispatcher m_dispatch;
};
}